//
//  ICPullComBoxCell.m
//  ICome
//
//  Created by zhangrongwu on 16/8/19.
//  Copyright © 2016年 iCom. All rights reserved.
//

#import "ICPullComBoxCell.h"
#import "ICHeaderFile.h"

@implementation ICPullComBoxCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self headImageView];
        [self titleLabel];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

- (void)setItem:(ICCommonItem *)item
{
    _item = item;
    
    [self setupData];
}

// 设置子控件数据
- (void)setupData {
    UIImage *headImg = [UIImage imageNamedFromiComeSDKBundle:_item.icon];
    self.headImageView.image = headImg;
    self.titleLabel.text = _item.title;
    
    [self.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_headImageView.mas_right).offset(12);
        make.centerY.equalTo(self.mas_centerY);
    }];
    if ([_item isKindOfClass:[ICComboxItem class]]) { // 下拉菜单
        [self.headImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.mas_left).offset(15);
            make.centerY.equalTo(self.mas_centerY);
            make.width.mas_equalTo(headImg.size.width * Level);
            make.height.mas_equalTo(headImg.size.height * Level);
        }];
        [self.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.headImageView.mas_right).offset(10);
            make.centerY.equalTo(self.mas_centerY);
        }];
    }
}


// 布局
- (void)layoutSubviews {
    self.leftFreeSpace = 15;
    [super layoutSubviews];
    self.titleLabel.font = [UIFont systemFontOfSize:16];
    [_titleLabel sizeToFit];
}


- (UIImageView *)headImageView {
    if (!_headImageView) {
        UIImageView *imageV = [[UIImageView alloc] init];
        [self.contentView addSubview:imageV];
        _headImageView = imageV;
    }
    return _headImageView;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        UILabel *label = [[UILabel alloc] init];
        [self.contentView addSubview:label];
        _titleLabel = label;
    }
    return _titleLabel;
}

@end
